package com.dfd.store.service.impl;

import java.sql.SQLException;
import java.util.List;

import com.dfd.store.dao.CategoryDao;
import com.dfd.store.dao.impl.CategoryDaoImpl;
import com.dfd.store.domain.Category;
import com.dfd.store.service.CategoryService;
import com.dfd.store.utils.BeanFactory;
import com.dfd.store.utils.JedisUtils;

import redis.clients.jedis.Jedis;

public class CategoryServiceImpl implements CategoryService {
	CategoryDao categorydao = (CategoryDao)BeanFactory.getName("CategoryDao");

	@Override
	public List<Category> getAllCats() throws SQLException {
		List<Category> allCats = categorydao.getAllCats();
		return allCats;
	}

	@Override
	public Category removeCategory(String cid) throws Exception {
		Category category = categorydao.removeCategory(cid);
		// 更新redis
		Jedis jedis = JedisUtils.getJedis();
		jedis.del("allCats");
		JedisUtils.closeJedis(jedis);
		return category;
	}

	@Override
	public void save(Category category) throws Exception {
		//
		categorydao.save(category);
		// 更新redis
		Jedis jedis = JedisUtils.getJedis();
		jedis.del("allCats");
		JedisUtils.closeJedis(jedis);

	}

	@Override
	public void edit(Category category) throws Exception {
		categorydao.edit(category);
		// 更新redis
		Jedis jedis = JedisUtils.getJedis();
		jedis.del("allCats");
		JedisUtils.closeJedis(jedis);
	}

	@Override
	public Category findById(String cid) throws Exception {
		Category category = categorydao.findById(cid);
		return category;
	}

}
